{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import datasets\n",
    "\n",
    "iris = datasets.load_iris()\n",
    "X = iris.data[:, :2]\n",
    "y = iris.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=666)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LogisticRegression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n",
       "          intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,\n",
       "          penalty='l2', random_state=None, solver='liblinear', tol=0.0001,\n",
       "          verbose=0, warm_start=False)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 默认 multi_class = 'ovr'\n",
    "log_reg = LogisticRegression()\n",
    "log_reg.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6578947368421053"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_decision_boundary(model, axis):\n",
    "    x0, x1 = np.meshgrid(\n",
    "        np.linspace(axis[0], axis[1], int((axis[1]-axis[0])*100)),\n",
    "        np.linspace(axis[2], axis[3], int((axis[3]-axis[2])*100))\n",
    "    )\n",
    "    x_new = np.c_[x0.ravel(), x1.ravel()]\n",
    "    \n",
    "    y_predict = model.predict(x_new)\n",
    "    zz = y_predict.reshape(x0.shape)\n",
    "    from matplotlib.colors import ListedColormap\n",
    "    custom_cmap = ListedColormap(['#EF9A9A', '#FFF59D', '#90CAF9'])\n",
    "    plt.contourf(x0, x1, zz, linewidth=5, cmap=custom_cmap)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\fangyang\\Anaconda3\\lib\\site-packages\\matplotlib\\contour.py:967: UserWarning: The following kwargs were not used by contour: 'linewidth'\n",
      "  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3X+w3HV97/Hn+/ww53BykhghJCTR4IBaG35EMrloKoI4nSYqyRWccseKdNpmbKtFreVeiheUkXHEji2Vjk7Ua8H2erWBS5CGjkWDAi0wCWgIBCm9EZOQECQkOQnnxJxz3veP3T3Zs9n9fr+73/1+v/vd7+sxk+Hs98fuZ7/n8D6f89nXvtfcHRER6X49WQ9ARETSoYIvIlIQKvgiIgWhgi8iUhAq+CIiBaGCLyJSEJELvpn1mtkTZnZvnX1Xm9lLZvbT8r8/bO8wRUQkrr4mjr0G2AHMarD/u+7+sfhDEhGRJESa4ZvZIuC9wDeSHY6IiCQl6gz/b4BrgeGAYy43s4uAZ4FPuvuu2gPMbB2wDmBoxowLzp4/v8nhioikp3cu7B99XdbDmGbXM4//yt1Pa+Xc0IJvZu8D9rv7VjO7uMFh3we+4+7HzOyjwO3Au2sPcvf1wHqAZUuW+Obrr29lzCIiiZvzoV5ufer3s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77wH+CvglsBc45O4/qDks1ToVcUzQZJ1KtOCb2fuA/e6+NeiwOtsSy4pGHNP3gSXufi5wPyd+sydppbu/DVgF/KmZXVSzP9XrVCVsXI9T+rP8POArwN0Jj6cPeBvwVXdfBhwF/kfNMWlfqyhjSvs6AWBmrwEuA/6p3u462xL/mQoZU+rXycxeS2kGfyZwBjBkZrUdCdOuU1HG1HSdSnqGvxK4zMx+Afwf4N1m9g81x+wGFgOU/3SZTbLdOUPH5O4vu/ux8s2vAxckOJ7KY75Q/u9+4P8CK2oOmbpOZYtow594ccfl6bfW2A3sdvdHy7c3UCq2tcekea1Cx5TBdapYBTzu7i/W2ZfJz1TQmDK6Tu8Bdrr7S+5+HLgLeEfNMWnXqdAxtVKnEi347n6duy9y9yWU/oT7kbvX/pa6B/hI+esrysck9pszyphq1jEvA3YkNZ7y4w2Z2XDla+C3gdpOovcAV5WTFRdS+hNvb9bjspRba7j7PmCXmVU6Bl4KPF1zWKrXKsqY0r5OVf4bjZdOUv+ZChtTRtfpl8CFZnZK+bEv5eT/51OtU1HG1FKdSvKV5ppXlC+m/Oo7cBNwWfnrAUp/2j0HPAa8sQPG9AXgKeBnwGbgLQmP443lx/pZ+XGvL2//KPDR8tcG/B3wn8CTwPIUrk+UcX2s6lo9ArwjhXGdD2wBtlH6k/+1HXCtwsaUxXU6hVKxnF21LevrFDam1K9T+XE/BzxDaULzbWBG1nUqwpiarlNqrSAiUhB6p62ISEGo4IuIFIQKvohIQajgi4gUhAq+iEhBqOCLiBSECr6ISEH8fyu9jtofpqGZAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x251a2cb07b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(log_reg, axis=[4,8.5,1.5,4.5])\n",
    "plt.scatter(X[y==0, 0], X[y==0, 1])\n",
    "plt.scatter(X[y==1, 0], X[y==1, 1])\n",
    "plt.scatter(X[y==2, 0], X[y==2, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,\n",
       "          intercept_scaling=1, max_iter=100, multi_class='multinomial',\n",
       "          n_jobs=1, penalty='l2', random_state=None, solver='newton-cg',\n",
       "          tol=0.0001, verbose=0, warm_start=False)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# sklearn中更改默认参数OvR为multinomial(即OvO), OvO比OvR更准确,但是计算开销是n^2\n",
    "# solver 需要相应修改为 newton-cg\n",
    "log_reg2 = LogisticRegression(multi_class='multinomial', solver='newton-cg')\n",
    "log_reg2.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7894736842105263"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg2.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\fangyang\\Anaconda3\\lib\\site-packages\\matplotlib\\contour.py:967: UserWarning: The following kwargs were not used by contour: 'linewidth'\n",
      "  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD8CAYAAAB0IB+mAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3X+Q3HWd5/Hne2ZCMk4mCYiYQMBggRLJIkgqh+TWQqAsCRZwAitX6MqWblZ3deO6t9axWIicFGV55ZqVLTXqnSh7/i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metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(log_reg2, axis=[4,8.5,1.5,4.5])\n",
    "plt.scatter(X[y==0, 0], X[y==0, 1])\n",
    "plt.scatter(X[y==1, 0], X[y==1, 1])\n",
    "plt.scatter(X[y==2, 0], X[y==2, 1])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用鸢尾花的所有数据进行分类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = iris.data\n",
    "y = iris.target\n",
    "\n",
    "X_train,X_test,y_train,y_test = train_test_split(X,y,random_state=666)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9473684210526315"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# OvR\n",
    "log_reg3 = LogisticRegression()\n",
    "log_reg3.fit(X_train, y_train)\n",
    "log_reg3.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_reg4 = LogisticRegression(multi_class='multinomial', solver='newton-cg')\n",
    "log_reg4.fit(X_train, y_train)\n",
    "log_reg4.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Sklearn中封装的 OvO 和 OvR 类\n",
    "可以将2分类/自定义分类器变成 多分类器"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9473684210526315"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.multiclass import OneVsRestClassifier\n",
    "\n",
    "ovr = OneVsRestClassifier(log_reg)\n",
    "ovr.fit(X_train, y_train)\n",
    "ovr.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.0"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.multiclass import OneVsOneClassifier\n",
    "\n",
    "ovo = OneVsOneClassifier(log_reg)\n",
    "ovo.fit(X_train, y_train)\n",
    "ovo.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
